package testng.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.iwhalecloud.citybrain.flow.platform.manager.FlowEngineApplication;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.NoticeRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.WorkingDayRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository.FlowReTimeoutSettingRepositoryImpl;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository.FlowRuTimeoutSettingRepositoryImpl;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.notice.FlowReNoticeInfo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.notice.NoticeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;

/**
 * @author fenghongjian
 * @description
 * @date 2019/7/12 14:35
 */
@SpringBootTest(classes = FlowEngineApplication.class)
public class NoticeServiceImplTest extends AbstractTransactionalTestNGSpringContextTests {

    @Autowired
    private NoticeRepository noticeRepository;

    @Autowired
    private FlowReTimeoutSettingRepositoryImpl flowReTimeoutSettingService;

    @Autowired
    private FlowRuTimeoutSettingRepositoryImpl flowRuTimeoutSettingService;

    @Autowired
    private WorkingDayRepository workingDayRepository;

    //@Test
    public void testSendNoticeToMessageCenter() throws Exception {
        List<NoticeInfo> list = new ArrayList<>();
        NoticeInfo info = new NoticeInfo();
        info.setRuNoticeChannelId("165");
        info.setType("SMS");
        info.setContent("发送短信渠道消息内容。");
        info.setAccount("FengHongJian");
        info.setAccountName("冯宏健");
        info.setTitle("短信通知");
        info.setName("短信通知模板");
        list.add(info);
//        NoticeInfo info1 = new NoticeInfo();
//        info1.setType("SYSTEM");
//        info1.setContent("发送系统通知渠道消息内容。");
//        info1.setAccount("roc");
//        info1.setAccountName("吴烈鹏");
//        info1.setTitle("系统通知通知");
//        info1.setName("系统通知模板");
//        list.add(info1);

        noticeRepository.sendNoticeToMessageCenter(list);
    }

//    //@Test
//    public void testSendSameNoticeTypeToMessageCenter() throws Exception {
//
//        List<NoticeInfo> list = new ArrayList<>();
//        NoticeInfo info = new NoticeInfo();
//        info.setAccount("FengHongJian");
//        info.setAccountName("冯宏健");
//        list.add(info);
//        NoticeInfo info1 = new NoticeInfo();
//        info1.setAccount("roc");
//        info1.setAccountName("吴烈鹏");
//        list.add(info1);
//
//        noticeService.sendSameNoticeTypeToMessageCenter(list, "钉钉通知", "钉钉通知模板", "DINGDING", "发送钉钉渠道消息内容。");
//    }

    //@Test
    public void testCopyReTimeoutSetting() {
        flowReTimeoutSettingService.copyReTimeoutSetting("3211c56da6ce11e9a6ad207918fcc7cd", "test01", "t_b_1596772", "");
    }

    //@Test
    public void listTaskHandleNotice() {
        List<NoticeInfo> noticeInfos = flowRuTimeoutSettingService.listTaskHandleNotice("test01", "t_b_1596772");
        System.out.println(noticeInfos);
    }

    //@Test
    public void listNeedNotifyTimeoutAndWarningNotice() {
        List<FlowReNoticeInfo> flowReNoticeInfos = flowRuTimeoutSettingService.listNeedNotifyTimeoutAndWarningNotice("1");
        System.out.println(flowReNoticeInfos);
    }

    //@Test
    public void isTimeout() throws ParseException {
        String start = "2019-07-06 14:00:00";
        String end = "2019-07-14 14:00:00";

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = simpleDateFormat.parse(start);
        Date endDate = simpleDateFormat.parse(end);

        workingDayRepository.isTimeout(startDate, endDate, 300000L);
    }
}